/*
 * Copyright Owen Watson 2009
 * 
 * This file is part of ArtNotes.
 *
 * ArtNotes is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.

 * ArtNotes is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with ArtNotes.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Drawing;
using MonoTouch.CoreGraphics;
using MonoTouch.CoreFoundation;

namespace ArtNotes
{
	/// <summary>
	/// The Tab Bar is one of two main navigation methods
	/// used within the application.
	/// The tabs on the tab bar allow navigation between
	/// the differing major components of the application
	/// i.e. Notebooks, Flickr, Map
	/// </summary>
	[MonoTouch.Foundation.Register("ANTabBarController")]
	public class ANTabBarController : UITabBarController
	{
		public ANTabBarController (IntPtr p) : base(p)
		{
		}

		public ANTabBarController ()
		{
		}
	
		private UINavigationController aboutController;
		private UINavigationController notebookController;
		private UINavigationController mapController;
		private UINavigationController searchController;
		private UINavigationController advancedController;
		
		//private UINavigationController flickrTestController;
		
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			UIViewController[] tabs = null;
			
			ANAboutTabController aboutTabController = new ANAboutTabController ();
			aboutController = new UINavigationController ();
			aboutController.PushViewController (aboutTabController, true);
			aboutController.TopViewController.Title = "About";
			aboutController.TabBarItem = new UITabBarItem ("About", UIImage.FromFile ("Images/about_tab_icon.png"), 0);
			
			ANNotebooksTabController notebookTabController = new ANNotebooksTabController ();
			notebookController = new UINavigationController ();
			notebookController.PushViewController (notebookTabController, true);
			notebookController.TopViewController.Title = "Notebooks";
			notebookController.TabBarItem = new UITabBarItem ("Notebooks", UIImage.FromFile ("Images/nb_tab_icon.png"), 0);

			ANImageSearchTabController searchTabController = new ANImageSearchTabController();
			searchController = new UINavigationController();
			searchController.PushViewController(searchTabController, true);
			searchController.TopViewController.Title = "Flickr";
			searchController.TabBarItem = new UITabBarItem ("Flickr", UIImage.FromFileUncached ("Images/flickr_tab_bar_2.png"), 0);

			ANMapViewTabController mapTabController = new ANMapViewTabController();
			mapController = new UINavigationController();
			mapController.PushViewController(mapTabController, true);
			mapController.TopViewController.Title = "Image Locations";
			mapController.TabBarItem = new UITabBarItem ("Map", UIImage.FromFileUncached ("Images/map_tab_icon.png"), 0);
			
			//ANFlickrResults flickrResultsController = new ANFlickrResults();
			//flickrTestController = new UINavigationController();
			//flickrTestController.PushViewController(flickrResultsController, true);
			//flickrTestController.TopViewController.Title = "Flickr Results";
			//flickrTestController.TabBarItem = new UITabBarItem ("Flickr", UIImage.FromFileUncached ("Images/map_tab_icon.png"), 0);

			if(AN_APP_OPTIONS.AN_ADVANCED)
			{
				Console.WriteLine("Adding Advanced Tab");
				ANAdvancedTabController advancedTabController = new ANAdvancedTabController();
				advancedController = new UINavigationController();
				advancedController.PushViewController(advancedTabController,true);
				advancedController.TopViewController.Title = "Tag Editor";
				advancedController.TabBarItem = new UITabBarItem("Tag Editor",UIImage.FromFile ("Images/search_tab_icon.png"), 0);
				
				tabs = new UIViewController[] {
					notebookController,
					searchController,
					mapController,
					advancedController,
					//flickrTestController,
					aboutController
				};
			}
			else
			{
				tabs = new UIViewController[] {
					notebookController,
					searchController,
					mapController,
					aboutController
				};
			}
			
			this.SelectedViewController = notebookController;
			this.ViewControllers = tabs;
			
			UIBarButtonItem btnBack = new UIBarButtonItem () { Title = "Back" };
			
			NavigationItem.BackBarButtonItem = btnBack;
			
			//UIImageView img = new UIImageView(UIImage.FromFileUncached("/Library/fatcat.jpg"));
			//RectangleF offSet = img.Frame;
			//offSet.Y ++;
			//img.Frame = offSet;

			//this.TabBar.InsertSubview(img,0);
			//this.TabBar.Frame = new RectangleF(this.TabBar.Frame.X,this.TabBar.Frame.Y - 10,this.TabBar.Frame.Width,this.TabBar.Frame.Height);
			//this.TabBar.Transform = CGAffineTransform.MakeRotation(0.05f);
			
			//this.NavigationController.NavigationBar.TintColor = UIColor.FromPatternImage(UIImage.FromFileUncached("/Library/scene3.jpg"));
			//this.NavigationController.NavigationBar.TintColor = UIColor.Red;
		}
	}
}
